package com.wcar.vipmanagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wcar.common.entity.UserIntegralLog;
import com.wcar.common.vo.Result;
import com.wcar.vipmanagement.dao.UserIntegralLogDao;
import com.wcar.vipmanagement.service.UserIntegralLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * @program: four-wcar-idea
 * @description:
 * @author: 张云龙
 * @create: 2024-06-05 10:43
 **/
@Service
public class UserIntegralLogServiceImpl implements UserIntegralLogService {

	@Autowired
	private UserIntegralLogDao userIntegralLogDao;

	@Override
	public Result selectIntegralByUserId(String id) {


		Integer expendScore = 0;
		try {
			QueryWrapper<UserIntegralLog> wrapper3 = new QueryWrapper<>();
			wrapper3.eq("user_id", id);
			wrapper3.select("sum(expend_score) as expendScore");
			UserIntegralLog userIntegralLog1 = userIntegralLogDao.selectOne(wrapper3);
			expendScore = userIntegralLog1.getExpendScore();

		} catch (Exception e) {
		}
		System.out.println(expendScore);
		Integer arrivalScore = 0;
		try {
			QueryWrapper<UserIntegralLog> wrapper4 = new QueryWrapper<>();
			wrapper4.eq("user_id", id);
			wrapper4.select("sum(arrival_score) as arrivalScore");
			UserIntegralLog userIntegralLog1 = userIntegralLogDao.selectOne(wrapper4);
			arrivalScore = userIntegralLog1.getArrivalScore();
		} catch (Exception e) {
		}
		System.out.println(arrivalScore);
		String s = String.valueOf(arrivalScore - expendScore);
		HashMap<Object, Object> hashMap = new HashMap<>();
		hashMap.put("credits", s);
		return new Result(200, "查询用户积分", hashMap);
	}


}
